package com.qiang.test04;

import java.io.*;

public class Demo01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day12\\aa.txt"));
        Student s = new Student("张三", 23);
        Student s2 = new Student("李四", 24);
        Student s3 = new Student("王五", 25);
        oos.writeObject(s);
        //oos.write("\r\n".getBytes());
        oos.writeObject(s2);
        //oos.write("\r\n".getBytes());
        oos.writeObject(s3);
        //oos.write("\r\n".getBytes());
        oos.close();


        ObjectInputStream oi = new ObjectInputStream(new FileInputStream("day12\\aa.txt"));
       /* Object o = oi.readObject();
        Student o1 = (Student) o;
        Object o2 = oi.readObject();
        Student o21 = (Student) o2;
        Object o3 = oi.readObject();
        Student o31 = (Student) o3;
        oi.close();
        System.out.println(o1);
        System.out.println(o21);
        System.out.println(o31);*/

        while (true) {
            try {
                Object o = oi.readObject();
                Student o1 = (Student) o;
                //oi.close();
                System.out.println(o1);
            } catch (IOException e) {
                break;
            }
        }
    }
}


